const http = require('http');
const url = require('url');
const qs = require('querystring');

// 创建一个web服务器
const server = http.createServer((req, res) => {
    // res.end('hello server');

    const { pathname } = url.parse(req.url);
    if(pathname === '/login') {
        // console.log(req.method);
        if(req.method === 'POST') {
            // 拿到body中的数据
            req.setEncoding('utf-8');
            req.on('data', (data) => {
                // console.log(data.toString()); 解码
                const { username, password } = JSON.parse(data); 
                console.log(username, password);
            })
        }
    }
})

// 启动服务器 
server.listen(8888, '0.0.0.0', () => {
    console.log('服务器启动成功');
})